package com.ruanhb.wsp.service;

import com.ruanhb.wsp.util.FileUtil;
import com.ruanhb.wsp.util.XstreamUtil;
import com.ruanhb.wsp.vo.City;
import com.ruanhb.wsp.vo.CityList;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.util.List;

/**
 * Created by r on 2018-8-30
 */
@Service
public class CityDataServiceImpl implements CityDataService {

    @Override
    public List<City> listCity() throws Exception {
        //读取xml文件
        File file = ResourceUtils.getFile("classpath:citylist.xml");

        String fileStr = FileUtil.readFile(file, "UTF-8");
        //xml转化java对象
        CityList cityList = XstreamUtil.parseFromXml(CityList.class,fileStr);

        return cityList.getCityList();
    }
}
